//
//  BConversionSelectTickerCurrencyController.m
//  GSBlockChain
//
//  Created by guoshikeji_a on 2019/1/8.
//  Copyright © 2019 guoshikeji. All rights reserved.
//

#import "BConversionSelectTickerCurrencyController.h"
//
#import "BConversionSelectTickerCurrencyCell.h"

@interface BConversionSelectTickerCurrencyController () <UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) UITableView *currencyTable;

@end

@implementation BConversionSelectTickerCurrencyController

- (void)viewDidLoad {
    [super viewDidLoad];
    //
    [self setupSubviews];
}
- (void)setupSubviews {
    [self.customNaviBar.leftButton setImage:nil forState:UIControlStateNormal];
    [self.customNaviBar.rightButton setImage:LOAD_IMAGE(@"general_close") forState:UIControlStateNormal];
    self.customNaviBar.rightButton.imageEdgeInsets = UIEdgeInsetsMake(0, 5, 0, 10);
    [self.customNaviBar layoutSubviews];
    //
    self.currencyTable = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
    self.currencyTable.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.currencyTable.dataSource = self;
    self.currencyTable.delegate = self;
    [self.view addSubview:self.currencyTable];
    [self.currencyTable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.customNaviBar.mas_bottom);
        make.left.bottom.right.mas_equalTo(self.view);
    }];
    //
    [self.currencyTable registerClass:BConversionSelectTickerCurrencyCell.class forCellReuseIdentifier:NSStringFromClass(BConversionSelectTickerCurrencyCell.class)];
    //
    UIView *safeFooter = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, Height_Bottom_SafeArea)];
    [self.currencyTable setTableFooterView:safeFooter];
}
- (void)didClickedNaviRightButton {
    [super didClickedNaviLeftButton];
}


#pragma mark - UITableViewDataSource,UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.conversionData.ticker.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    BCConversionDataTickerModel *model = self.conversionData.ticker[indexPath.row];
    BConversionSelectTickerCurrencyCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(BConversionSelectTickerCurrencyCell.class)];
    cell.model = model;
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 50.0;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    BCConversionDataTickerModel *model = self.conversionData.ticker[indexPath.row];
    if (model) {
        if (self.delegate && [self.delegate respondsToSelector:@selector(conversionSelectTickerCurrencyControllerDidSelectModel:)]) {
            [self.delegate conversionSelectTickerCurrencyControllerDidSelectModel:model];
        }
        [self didClickedNaviRightButton];
    }
}

@end
